package lib;

import org.apache.poi.ss.usermodel.Row;

public class RowInLib 
{
	private Row m_row;
	private boolean m_isEmpty;
	
	public RowInLib(Row row)
	{
		m_row = row;
		m_isEmpty = m_row == null;
		if(m_isEmpty)
		{
			return;
		}
		int len = m_row.getLastCellNum();
		//if(len <= Config.NULL_ROW_LENGTH)
		//{
		for(int i = 0; i <= len; ++i)
		{
			CellInLib cell = new CellInLib(m_row.getCell(i));
			if(!cell.IsEmpty() && cell.getValue().compareTo("") != 0)
			{
				return;
			}
		}
		//}
		m_isEmpty = true;
		m_row = null;
	}
	
	public RowInLib(Row row, int len)
	{
		m_row = row;
		m_isEmpty = false;
		for(int i = 0; i < len; ++i)
		{
			m_row.createCell(i);
		}
	}
	
	public boolean isEmpty()
	{
		return m_isEmpty;
	}
	
	protected Row getRealRow()
	{
		return m_row;
	}
	
	public int getCellNumber()
	{
		if(m_isEmpty)
		{
			return 0;
		}
		return m_row.getLastCellNum();
	}
	
	public int getNotEmptyCellNumber()
	{
		if(m_isEmpty)
		{
			return 0;
		}
		return m_row.getPhysicalNumberOfCells();
	}
	
	public CellInLib getCell(int index)
	{
		if(m_isEmpty)
		{
			return new CellInLib(null);
		}
		return new CellInLib(m_row.getCell(index));
	}
}
